package org.ala.tiktools.generator.mybatis.creator.entity.fields;

import freemarker.template.TemplateException;
import org.ala.tiktools.generator.mybatis.config.info.Part;
import org.ala.tiktools.generator.mybatis.creator.AbstractCreator;
import org.ala.tiktools.generator.mybatis.creator.entity.EntityCreator;
import org.ala.tiktools.generator.mybatis.creator.entity.EntityInfo;
import org.ala.tiktools.generator.mybatis.dbinfo.TableInfo;
import org.ala.tiktools.generator.mybatis.tools.Tools;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ala
 * @date 2025-03-17 11:30
 */
public class EntityFieldsCreator extends AbstractCreator {
    /**
     *  生成Entity类
     */
    public EntityFieldsInfo create(Part p, EntityInfo e, TableInfo t) throws IOException, TemplateException {
        Map<String, Object> dataMeta = new HashMap<>();
        EntityFieldsInfo f = EntityFieldsInfo.build(p, e, t);
        dataMeta.put("f", f);

        String out = e.getPkg();
        out = this.getOutRootPath() + out.replaceAll("\\.", "/");
        Tools.existsAndMakeDirs(out);
        out = out + "/" + f.getClassName() + ".java";

        output("EntityField.ftl", dataMeta, out);

        System.out.println("生成EEntityField类. path:" + out);
        return f;
    }
}
